package jmu.cultural_tourism.service.impl;

import jmu.cultural_tourism.entity.PostInfo;
import jmu.cultural_tourism.entity.PostReply;
import jmu.cultural_tourism.dao.PostReplyDao;
import jmu.cultural_tourism.service.PostReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import jakarta.annotation.Resource;

import java.util.List;

/**
 * (PostReply)表服务实现类
 *
 * @author makejava
 * @since 2025-07-17 15:31:34
 */
@Service("postReplyService")
public class PostReplyServiceImpl implements PostReplyService {
    @Autowired
    private PostReplyDao postReplyDao;

    /**
     * 通过ID查询单条数据
     *
     * @param replyId 主键
     * @return 实例对象
     */
    @Override
    public PostReply queryById(Integer replyId) {
        return this.postReplyDao.queryById(replyId);
    }

    @Override
    public List<PostReply> queryByPostId(Integer postId) {
        return postReplyDao.queryByPostId(postId);
    }

    /**
     * 分页查询
     *
     * @param postReply   筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<PostReply> queryByPage(PostReply postReply, PageRequest pageRequest) {
        long total = this.postReplyDao.count(postReply);
        return new PageImpl<>(this.postReplyDao.queryAllByLimit(postReply, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param postReply 实例对象
     * @return 实例对象
     */
    @Override
    public PostReply insert(PostReply postReply) {
        this.postReplyDao.insert(postReply);
        return postReply;
    }

    /**
     * 修改数据
     *
     * @param postReply 实例对象
     * @return 实例对象
     */
    @Override
    public PostReply update(PostReply postReply) {
        this.postReplyDao.update(postReply);
        return this.queryById(postReply.getReplyId());
    }

    /**
     * 通过主键删除数据
     *
     * @param replyId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer replyId) {
        return this.postReplyDao.deleteById(replyId) > 0;
    }
}
